
import Config from '~/config';
let {CONSOLE} = Config;

let chalk = process.env.NODE_ENV !== 'development' ? {
  cyan (string) {
    return string;
  },
  red (string) {
    return string;
  },
  blue (string) {
    return string;
  },
  green (string) {
    return string;
  },
} : require('chalk');

const consoleOutPut = chalk.cyan('\t---->\t');

function check (level) {
  if (CONSOLE.use) {
    if (level >= CONSOLE.level) {
      return true;
    }
  }
  return false;
}

class Log {
  constructor (level = 1, outPut = consoleOutPut) {
    this._cons = '';
    this._consH = '';
    this.level = level;
    this._consoleOutPut = chalk.cyan(outPut);
  };
  set l (string) {
    if (check(this.level)) {
      if (string.constructor === Function) {
        string = string(chalk);
      }
      this._cons += this._consoleOutPut + string + '\n';
    }
  };
  set lE (string) {
    if (check(this.level)) {
      if (string.constructor === Function) {
        string = string(chalk);
      }
      this._cons += this._consoleOutPut + chalk.red(string) + '\n';
    }
  };
  set lH (string) {
    if (check(this.level)) {
      if (string.constructor === Function) {
        string = string(chalk);
      }
      this._consH = `
----------------------------------------------------------------
${string}
    过程：
`;
    }
  };
  log () {
    if (this._consH) {
      console.log(this._consH + this._cons + '----------------------------------------------------------------\n');
    } else {
      console.error('存在没有头的log输出！');
      // console.log('----------------------------------------------------------------\n' + this._cons + '----------------------------------------------------------------\n');
    }
    this._cons = '';
    this._consH = '';
  };
}

let cons = new Log();

const showInfo = '\t\t\t\t';

export {Log, cons, showInfo};
